#include "KohonenConnector.h"
#include "PositionNeuron.h"
#include "../INeuron.h"
#include "KohonenSynapse.h"
#include "../Initializers/RandomFunction.h"
#include "../ConnectionMode.h"

using namespace NeuralPlusPlus::Core;
using namespace NeuralPlusPlus::Core::SOM;
using namespace NeuralPlusPlus::Core::Initializers;

NeuralPlusPlus::Core::SOM::KohonenConnector::KohonenConnector( KohonenLayer *sourceLayer, KohonenLayer *targetLayer ) : Connector(sourceLayer, targetLayer, ConnectionModeType::Complete)
	{
	this->Initializer = new RandomFunction();
	ConstructSynapses();
	}

void NeuralPlusPlus::Core::SOM::KohonenConnector::ConstructSynapses()
	{
	int targetLayerNeuronLength = TargetLayer->NeuronsLength;
	int sourceLayerNeuronLength = SourceLayer->NeuronsLength;
	for (int i = 0; i < targetLayerNeuronLength;i++ )
		{
		PositionNeuron *targetNeuron = (PositionNeuron*)(*TargetLayer)[i];
		for (int j = 0; j < sourceLayerNeuronLength;j++ )
			{
			PositionNeuron *sourceNeuron = (PositionNeuron*)(*SourceLayer)[j];
			Synapses[i * sourceLayerNeuronLength + j] = new KohonenSynapse(sourceNeuron, targetNeuron, this);
			}
		}
	}

void NeuralPlusPlus::Core::SOM::KohonenConnector::Initialize()
	{
	if (Initializer != NULL)
		{
		Initializer->Initialize(this);
		}
	}